import Axios from "Axios";
import {
    UPDATE_STATE,
    UPDATE_SESSIONSTORAGE
} from './mutation-types';

let convert = (level) => {
    let aliasName = '';
    switch (parseInt(level)) {
        case 1: aliasName = '简单'; break;
        case 2: aliasName = '中等'; break;
        case 3: aliasName = '困难'; break;
        default:
            aliasName = '自定义'; break;
    }
    return aliasName;
}

const config = () => {
    return new Promise((resolve, reject) => {
        Axios({
            url: '/apis/minesConfigList',
            method: 'post',
        }).then((response) => {
            let minesConfig = {};
            let { code, data, msg } = response.data;
            if (code == 0) {
                data.map((value, index) => {
                    let {
                        configid,//配置id
                        alias,//别名
                        level,//难度代号(1:简单,2:中等:3:困难,4:自定义)
                        specification,//游戏结构
                        amount,//炸弹数量
                        isUserConfig,//是否是用户配置0:否,1:是
                        timeBonus,//时间奖励,
                        completeBonus,//完成奖励
                        dissolveBonus,//消灭奖励
                    } = value;
                    let [x, y] = specification.split('*');
                    let aliasName = convert(level);

                    minesConfig[alias] = {
                        configid,
                        alias,
                        level,
                        aliasName,
                        x: parseInt(x),
                        y: parseInt(y),
                        amount: parseInt(amount),
                        timeBonus: parseInt(timeBonus),
                        completeBonus: parseInt(completeBonus),
                        dissolveBonus: parseInt(dissolveBonus),
                        isUserConfig,
                        flags: parseInt(amount),
                        flagMode: false,//是否插旗模式
                        gameState: 0,//默认游戏状态(0:初始化,1:游戏进行中,2游戏暂停中,3游戏结束玩家win,4游戏借宿)
                        piece: 40,//方块大小
                    }
                })
                resolve(minesConfig)
            } else {
                reject()
            }
        })
    })
}
const bestScore=()=>{
    return new Promise((resolve, reject)=>{
        // Axios({
        //     url:'/apis/'
        // })
    })
}
export default {
    async getMinesConfig({ commit, state }) {
        let res = await config();
        commit(UPDATE_STATE, res)
    },
}